package www.test.utils;

import javax.servlet.http.HttpServlet;

public class PageUtils  
{
	//每页显示的条数
	private  int pageSize=5;
	//总共的条数
	private  int recordCount;
	//当前页面
	private static  int currentPage=1;
	public void PageUtils(int pageSize,int recordCount,int currentPage)
	{
		this.pageSize=pageSize;
		this.recordCount=recordCount;
		this.currentPage=currentPage;
	}
	public PageUtils(int recordCount)
	{
		PageUtils(15,recordCount,getCurrentPage());
	}
	//总页数
	public int getPageCount()
	{
		int size = recordCount/pageSize;
		int mod =recordCount%pageSize;
		if(mod!=0)
		
		size++;
		return recordCount==0?1:size;
		
		
	}
	//索引 包含起始索引为o
	public int getFromIndex()
	{
		return (currentPage-1)*pageSize;
	}
	
	// 不包含
	public int getToIndex()
	{
		return Math.min(recordCount, currentPage*pageSize);
	}
	
	
	
	
	//当页
	public void setCurrentPage(int currentPage)
	{
		int validPage =currentPage<=0?1:currentPage;
		validPage=validPage>getPageCount()?getPageCount():validPage;
		this.currentPage = currentPage;
	}
	
	public static int getCurrentPage()
	{
		return currentPage;
	}
	
	/**
	 * 每页显示的条数
	 */
	public int getPageSize()
	{
		return pageSize;
	}
	public void setPageSize(int pageSize)
	{
		this.pageSize = pageSize;
	}
	
	
	/**
	 * 总共的条数
	 * @return
	 */
	
	public int getRecordCount()
	{
		return recordCount;
	}
	public void setRecordCount(int recordCount)
	{
		this.recordCount = recordCount;
	}
	

}
